﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Admin_User_inc.aspx.cs" Inherits="newBlog.CenterInc.view_inc.admin.Admin_User_inc" %>
<%@ Import Namespace="newBlog.CenterInc.Ctrltor" %>
<%@ Import Namespace="newBlog.CenterInc.tool" %>
<%  Response.ContentType = "application/json";
    if (Session["user_id"]==null) {
        Response.Write("{\"error\":\"您未登录本站\"}");
        return;
    }
    if (Convert.ToInt32(Session["user_grade"])!=1) { 
    Response.Write("{\"error\":\"您不是管理员\"}");
        return;
    }
    int mode = (Request.QueryString["mode"]==null||Request.QueryString["mode"].Length==0)?0:Convert.ToInt32(Request.QueryString["mode"]);//1修改审核状态 2修改用户 3删除用户 4修改权限
    string user_id =( Request.Form["user_id"]==null|| Request.Form["user_id"].Length==0)?"": Request.Form["user_id"];
    User_inc user_Inc = new User_inc();
    isString isString = new isString();
    string grade;
    switch (mode) {
        case 1:
            if (user_id.Length==0) {
                Response.Write("{\"error\":\"您未选择要删除的用户\"}");
                return;
            }
            if (Session["user_id"].Equals(user_id)) {
                Response.Write("{\"error\":\"您不能删除您自己\"}");
                return;
            }
            if (user_Inc.examine(user_id)) {
                Response.Write("{\"error\":\"删除失败\"}");
                return;
            }
            Response.Write("{\"msg\":\"删除成功\"}");
            return;
        case 2:
            string Password=( Request.Form["Password"]==null|| Request.Form["Password"].Length==0)?"": Request.Form["Password"];
            string email=( Request.Form["email"]==null|| Request.Form["email"].Length==0)?"": Request.Form["email"];
            string balance=( Request.Form["balance"]==null|| Request.Form["balance"].Length==0)?"": Request.Form["balance"];
            grade=( Request.Form["grade"]==null|| Request.Form["grade"].Length==0)?"": Request.Form["grade"];
            if (isString.isEmpty(Password,email,balance)) {
                Response.Write("{\"error\":\"不能有空\"}");
                return;
            }
            if (user_Inc.UpUser(Password,email,balance,grade,user_id)) { 
                Response.Write("{\"error\":\"修改失败\"}");
                return;
            }
            Response.Write("{\"msg\":\"修改成功\"}");
            return;
        case 4:
            grade=( Request.Form["grade"]==null|| Request.Form["grade"].Length==0)?"": Request.Form["grade"];
            if (grade.Length==0) {
                Response.Write("{\"error\":\"您未选择权限名\"}");
                return;
            }
            if (user_id.Length==0) {
                Response.Write("{\"error\":\"您未选择要删除的用户\"}");
                return;
            }
            if (Session["user_id"].Equals(user_id)) {
                Response.Write("{\"error\":\"您不能修改您自己\"}");
                return;
            }
            if (user_Inc.UpGrade(user_id,grade)) {
                Response.Write("{\"error\":\"修改失败\"}");
                return;
            }
            Response.Write("{\"msg\":\"修改成功\"}");
            return;
        
    }
    %>